package com.yihaodian.search.query.converter;

import org.apache.lucene.search.Sort;
import org.apache.lucene.search.SortField;

public class SortConverter {
	public static Sort convert(com.yihaodian.api.search.misc.SearchSort sort) {
		Sort ret = new Sort();
		
		SortField[] sfs = null;
		com.yihaodian.api.search.misc.SearchSortField[] fields = sort.getFields();
		if(fields != null) {
			sfs = new SortField[fields.length];
			
			for(int i = 0; i < fields.length; ++ i) {
				// FIXME: set field type as REWRITEABLE
				// TODO: get field type from schema
				sfs[i] = new SortField(fields[i].getFieldName(), SortField.Type.REWRITEABLE, fields[i].isReverse());
			}
			ret.setSort(sfs);
		}
				
		return ret;
		
	}
}
